#include<bits/stdc++.h>
#define ll long long
//#define int long long 
using namespace std;
bool st;
const int N = 1e6+5,mod = 6661;
int c[mod][mod],s[mod][mod];
inline void init()
{
	c[0][0] = 1;
	for(int i = 1;i<mod;i++)
	{
		c[i][0] = 1;
		for(int j = 1;j<=i;j++) c[i][j] = (c[i-1][j-1]+c[i-1][j])%mod;
	}
	for(int i = 0;i<mod;i++)
	{
		s[i][0] = c[i][0]; 
		for(int j = 1;j<=i;j++) s[i][j] = (s[i][j-1]+c[i][j])%mod;
		for(int j = i+1;j<mod;j++) s[i][j] = s[i][j-1];
	}
}
inline int calc(int x,int r)
{
	int x1 = x%mod,x2 = x/mod;
	int r1 = r%mod,r2 = r/mod;
	int res = c[x1][r1]*c[x2][r2]%mod;
	if(r1) (res+=s[x1][r1-1]*c[x2][r2])%=mod;
	if(r2) (res+=s[x1][mod-1]*s[x2][r2-1])%=mod;
	return res;
}
int n,m;
ll k;
bool en;
struct node{
	int l,r;
	int v1,v2,res;
	inline friend bool operator < (node x,node y)
	{
		return x.l<y.l;
	}
};
inline node make(int lt,int rt,int v1,int v2)
{
	return (node){lt,rt,v1,v2,(calc(v1,rt-v2)-calc(v1,lt-1-v2)+mod)%mod};
}
set<node> ss; 
signed main()
{
	freopen("izumi.in","r",stdin);
	freopen("izumi.out","w",stdout);
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	init();
	cerr<<"Memory:"<<(&st-&en)/1024/1024<<"MB\n";
	cin>>n>>m>>k;
	k%=mod*mod;
	ss.insert(make(1,n,k,0));
	while(m--)
	{
		int op,x,y;
		ll z;
		cin>>op>>x>>y;
		if(op==1)
		{
			cin>>z;
			z%=mod*mod;
			auto p = ss.lower_bound((node){x+1,0,0,0});
			p--;
			node lt = *p,rt;
			while(p!=ss.end()&&p->l<=y)
			{
				rt = *p;
				p = ss.erase(p);
			}
			if(lt.l<x) ss.insert(make(lt.l,x-1,lt.v1,lt.v2));
			ss.insert(make(x,y,z,x-1));
			if(rt.r>y) ss.insert(make(y+1,rt.r,rt.v1,rt.v2));
		}
		else
		{
			auto p = ss.lower_bound((node){x+1,0,0,0});
			p--;
			node lt = *p,rt;
			int res = 0;
			while(p!=ss.end()&&p->l<=y)
			{
				if(p->l>x&&p->r<y) (res+=p->res)%=mod;
				rt = *p;
				p++;
			}
			(res+=make(x,min(lt.r,y),lt.v1,lt.v2).res)%=mod;
			if(rt.l!=lt.l) (res+=make(max(rt.l,x),y,rt.v1,rt.v2).res)%=mod;
			cout<<res<<'\n';
		}
	}
	return 0;
}

